package com.qkst.website.backstage.service.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.qkst.website.backstage.bean.CatalogBean;
import com.qkst.website.backstage.mapper.CatalogMapper;
import com.qkst.website.backstage.service.CatalogService;
/**
 * @author lh
 * @description 产品目销售目录service 业务处理层
 * @date 2017-05-05
 * @email ahlxlihao@163.com
 *
 */
@Service("catalogService")
@Transactional
public class CatalogServiceImpl implements CatalogService {
	@Autowired
	private CatalogMapper catalogMapper;

	/**
	 * 获取销售目录
	 * @param catalog
	 * @return List<CatalogBean>
	 */
	
	@Override
	public List<CatalogBean> list(CatalogBean catalog) {
		return catalogMapper.selectCatalogs(catalog);
	}
	/**
	 * 保存销售目录
	 * @param catalog
	 * @return CatalogBean
	 */
	@Override
	public CatalogBean save(CatalogBean catalog) {
		catalog.setCreateTime(new Date());
		catalog.setLastUpdate(new Date());
		catalogMapper.insert(catalog);
		return catalog;
	}
	
	/**
	 * 删除销售目录
	 * @param catalog
	 * @return boolean
	 */
	@Override
	public boolean delete(CatalogBean catalog) {
		//检查catalog下是否有目录
		//如果没有产品目录删除销售目录
		int num=catalogMapper.deleteByPrimaryKey(catalog.getCatalogId());
		if(num>0){
			return true;
		}
		//否则不允许删除
		return false;
	}

}
